package com.soilflow.common.exception;

import com.soilflow.common.utils.StringUtils;

/**
 * @author: csh
 * @date: 2022/8/22 10:35 AM
 */
public class AssertUtil {

    public static void assertNullAndThrow(Object str, String errorMsg) {
        if (str instanceof String && StringUtils.isEmpty((String) str)) {
            throw new ServiceException(errorMsg);
        }
        if (str == null) {
            throw new ServiceException(errorMsg);
        }
    }

    public static void assertNullAndThrow(Object str, String errorMsg, int i) {
        if (str instanceof String && StringUtils.isEmpty((String) str)) {
            throw new ServiceException("第" + i + "行数据 " + errorMsg);
        }
        if (str == null) {
            throw new ServiceException("第" + i + "行数据 " + errorMsg);
        }
    }

    public static void assertFalseAndThrow(boolean condition, String errorMsg) {
        if (!condition) {
            throw new ServiceException(errorMsg);
        }
    }
}
